Skip to content

CI: unpin pyarrow, fix failing test #51175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 10, 2023
Merged

Conversation

lukemanley
Copy link
Member

@lukemanley lukemanley commented Feb 5, 2023

Unpins pyarrow and fixes test_from_sequence_of_strings_pa_array which was xfailed for pyarrow duration types.

pyarrow 11.0 introduces support for casting from duration to string:

In [4]: pa.array([1], type=pa.duration("s")).cast(pa.string())
Out[4]: 
<pyarrow.lib.StringArray object at 0x7f77ed6cc9a0>
[
  "1"
]

pyarrow < 11.0 raises:

ArrowNotImplementedError: Unsupported cast from duration[s] to utf8 using function cast_string

@lukemanley lukemanley added CI Continuous Integration Arrow pyarrow functionality labels Feb 5, 2023
@lukemanley lukemanley marked this pull request as draft February 5, 2023 01:42
@lukemanley lukemanley marked this pull request as ready for review February 5, 2023 03:19
if isinstance(strings, (pa.Array, pa.ChunkedArray)):
scalars = strings
else:
scalars = pa.array(strings, type=pa.string(), from_pandas=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO (slightly) I think we should still prefer to use to_timedelta first if a non-pyarrow scalars was passed over the cast

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using to_timedelta first would be incorrect in some cases. For instance, if passed "1000 seconds" as

ArrowExtensionArray._from_sequence_of_strings(["1000"], dtype=pa.duration("s"))

pd.to_timedelta(["1000"]) is interpreted as 1000 ns (to_timedelta does not allow specifying unit with a string input and assumes nanoseconds).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, the example provided above errors on main due to assuming ns units:

import pyarrow as pa

ArrowExtensionArray._from_sequence_of_strings(["1000"], dtype=pa.duration("s"))

# ArrowInvalid: Casting from duration[ns] to duration[s] would lose data: 1000

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW there's a corner case with iNaT that pyarrow will handle differently from to_timedelta

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point re: NaT. I made some changes which now call to_timedelta first and only attempts the int conversion when the pyarrow unit is non-nano. It respects the null mask from to_timedelta so I think the NaT edge case is handled. I added a test for it.

It all feels a bit messy, but I don't see another option ATM. Open to suggestions.

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay. Just a merge conflict

@mroeschke mroeschke added this to the 2.0 milestone Feb 10, 2023
@mroeschke mroeschke merged commit 5f584bd into pandas-dev:main Feb 10, 2023
@mroeschke
Copy link
Member

Thanks @lukemanley

@phofl
Copy link
Member

phofl commented Feb 10, 2023

I guess we should add 11 to our build matrix?

@mroeschke
Copy link
Member

Good point. Otherwise 11 is only running on the macos and windows builds. Want to open a PR?

phofl pushed a commit to phofl/pandas that referenced this pull request Feb 10, 2023
* unpin pyarrow, fix failing test

* cleanup

* handle NaT/NaN
@lukemanley lukemanley deleted the unpin-pyarrow branch February 23, 2023 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality CI Continuous Integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI: pyarrow 11 broke ci
4 participants